Skip to content

feat(gmail): add list_emails_structured tool for programmatic email retrieval#115

Merged
dimavedenyapin merged 2 commits intomainfrom
feat/structured-email-list
Apr 3, 2026
Merged

feat(gmail): add list_emails_structured tool for programmatic email retrieval#115
dimavedenyapin merged 2 commits intomainfrom
feat/structured-email-list

Conversation

@dimavedenyapin
Copy link
Copy Markdown

@dimavedenyapin dimavedenyapin commented Apr 3, 2026

Summary

  • Adds output_format parameter to the existing read_emails tool — when set to "structured", returns machine-parseable JSON instead of human-readable text
  • Backward compatible: without output_format (or with "text"), behavior is unchanged
  • Also adds label_ids and include_headers optional params for structured mode filtering
  • Designed for consumption by workflow-builder Gmail trigger nodes (step 1 of Gmail incoming email trigger feature)

Usage

Default (text) — unchanged behavior

{ "query": "is:unread", "max_results": 5 }

Returns: "Found 5 emails:\n\nID: msg_001\nFrom: ..."

Structured JSON output

{ "query": "is:unread", "output_format": "structured", "label_ids": ["INBOX"], "max_results": 10 }

Returns:

{
  "emails": [
    {
      "id": "msg_001",
      "threadId": "thread_001",
      "historyId": "12345",
      "from": "alice@example.com",
      "to": "bob@example.com",
      "cc": "", "bcc": "",
      "subject": "Hello",
      "date": "Mon, 31 Mar 2026 10:00:00 +0000",
      "snippet": "...",
      "labels": ["INBOX", "UNREAD"],
      "isUnread": true,
      "messageId": "<abc@mail.gmail.com>",
      "body": { "text": "...", "html": "..." },
      "attachments": [{ "filename": "...", "mimeType": "...", "size": 1024, "attachmentId": "..." }]
    }
  ],
  "resultCount": 1,
  "query": "is:unread"
}

New optional parameters on read_emails

Parameter Type Description
output_format "text" | "structured" Output format (default: "text")
label_ids string[] Filter by Gmail label IDs (structured mode)
include_headers string[] Extra headers to extract (structured mode)

Test plan

  • 14 unit tests: structured output, empty results, multi-email, body on/off, attachments on/off, query passthrough, label_ids filter, max_results cap, extra headers, valid JSON, text format default, text format explicit
  • Verify black formatting passes in CI
  • Integration test with workflow-builder Gmail trigger node (sibling subtask)

🤖 Generated with Claude Code

dimavedenyapin and others added 2 commits April 3, 2026 09:54
…etrieval

Add a new `list_emails_structured` tool that returns emails as structured
JSON, designed for consumption by workflow-builder trigger nodes and
automation workflows. Unlike `read_emails` which returns human-readable
text, this tool outputs machine-parseable JSON with typed fields.

Features:
- Structured JSON output with emails array, resultCount, and query
- Optional filters: query, label_ids, max_results (capped at 100)
- Toggleable body and attachment inclusion via include_body / include_attachments_info
- Extra header extraction via include_headers parameter
- Each email includes: id, threadId, historyId, from, to, cc, bcc,
  subject, date, snippet, labels, isUnread, messageId

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…parate tool

Replace the standalone list_emails_structured tool with an output_format
parameter on the existing read_emails tool. When output_format='structured'
is passed, read_emails returns structured JSON; otherwise it returns the
original human-readable text format (backward compatible).

Also adds label_ids and include_headers params to read_emails for
structured mode filtering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dimavedenyapin dimavedenyapin merged commit 7211713 into main Apr 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant